package com.buaa.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

public class LimitQueue<E> implements Queue<E> {

	private int limit;

	Queue<E> queue;

	public LimitQueue(int limit) {
		this.limit = limit;
		queue = new LinkedList<E>();
	}

	/**
	 * 包含元素
	 */
	@Override
	public boolean contains(Object o) {
		return queue.contains(o);
	}

	/**
	 * 删除对象
	 */
	@Override
	public boolean remove(Object o) {
		return queue.remove(o);
	}

	/**
	 * 队尾追加元素
	 * @param e
	 * @return
	 */
	public E push(E e) {
		E ret = null;
		if (queue.size() >= limit)
			ret = queue.poll();
		queue.add(e);
		return ret;
	}

	/**
	 * 队尾追加元素
	 */
	@Override
	public boolean add(E e) {
		if (queue.size() >= limit)
			queue.poll();
		return queue.add(e);
	}

	/**
	 * 弹出队头元素
	 */
	@Override
	public E poll() {
		return queue.poll();
	}

	@Override
	public int size() {
		return 0;
	}

	@Override
	public boolean isEmpty() {
		return false;
	}

	@Override
	public Iterator<E> iterator() {
		return null;
	}

	@Override
	public Object[] toArray() {
		return null;
	}

	@Override
	public <T> T[] toArray(T[] a) {
		return null;
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		return false;
	}

	@Override
	public boolean addAll(Collection<? extends E> c) {
		return false;
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		return false;
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		return false;
	}

	@Override
	public void clear() {

	}

	@Override
	public boolean offer(E e) {
		return false;
	}

	@Override
	public E remove() {
		return null;
	}

	@Override
	public E element() {
		return null;
	}

	@Override
	public E peek() {
		return null;
	}

}
